package com.turnengine.client.local.group.bean;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Group.
 */
public class Group implements IGroup, Comparable<IGroup> {

	/** The id. */
	private int id = -1;
	/** The name. */
	private String name = "";
	/** The faction id. */
	private int factionId = -1;
	/** The parent id. */
	private int parentId = -1;

	/**
	 * Creates a new Group.
	 */
	public Group() {
	}

	/**
	 * Creates a new Group.
	 * @param id the id
	 * @param name the name
	 * @param factionId the faction id
	 * @param parentId the parent id
	 */
	public Group(int id, String name, int factionId, int parentId) {
		setId(id);
		setName(name);
		setFactionId(factionId);
		setParentId(parentId);
	}

	/**
	 * Creates a new Group.
	 * @param group the group
	 */
	public Group(Group group) {
		setId(group.getId());
		setName(group.getName());
		setFactionId(group.getFactionId());
		setParentId(group.getParentId());
	}

	/**
	 * Creates a new Group.
	 * @param iGroup the i group
	 */
	public Group(IGroup iGroup) {
		setId(iGroup.getId());
		setName(iGroup.getName());
		setFactionId(iGroup.getFactionId());
		setParentId(iGroup.getParentId());
	}

	/**
	 * Returns the id.
	 * @return the id.
	 */
	public int getId() {
		return id;
	}

	/**
	 * Returns the name.
	 * @return the name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the faction id.
	 * @return the faction id.
	 */
	public int getFactionId() {
		return factionId;
	}

	/**
	 * Returns the parent id.
	 * @return the parent id.
	 */
	public int getParentId() {
		return parentId;
	}

	/**
	 * Sets the id.
	 * @param id the id to set.
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Sets the name.
	 * @param name the name to set.
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Sets the faction id.
	 * @param factionId the faction id to set.
	 */
	public void setFactionId(int factionId) {
		this.factionId = factionId;
	}

	/**
	 * Sets the parent id.
	 * @param parentId the parent id to set.
	 */
	public void setParentId(int parentId) {
		this.parentId = parentId;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(631, 37);
		hash.append(id);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof Group) {
			Group compare = (Group) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.id, compare.id);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IGroup compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.id, compare.getId());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("id", id);
		if (name != null) {
			string.append("name", name);
		}
		string.append("factionId", factionId);
		string.append("parentId", parentId);
		return string.toString();
	}
}
